package club.beimeng.eduservice.controller;

import club.beimeng.commonutils.R;
import club.beimeng.eduservice.entity.EduCourse;
import club.beimeng.eduservice.entity.EduTeacher;
import club.beimeng.eduservice.service.EduCourseService;
import club.beimeng.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice")
@CrossOrigin
public class IndexController {

    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;

    @ApiOperation("热门课程和前四条名师")
    @GetMapping("index")
    public R index(){
        // 查询前八条热门课程
        QueryWrapper<EduCourse> eduCourseQueryWrapper = new QueryWrapper<>();
        eduCourseQueryWrapper.orderByDesc("view_count");
        eduCourseQueryWrapper.last("limit 8");
        List<EduCourse> courseList = courseService.list(eduCourseQueryWrapper);
        // 查询前四个名师
        QueryWrapper<EduTeacher> eduTeacherQueryWrapper = new QueryWrapper<>();
        eduTeacherQueryWrapper.orderByDesc("sort");
        eduTeacherQueryWrapper.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(eduTeacherQueryWrapper);

        return R.ok().data("courseList",courseList).data("teacherList",teacherList);
    }

}
/*
 *
 * @author Mr.Bao
 * @date 2021/8/4 12:31
 */